package com.biocar.service.impl;

import com.biocar.bean.Charge;
import com.biocar.mapper.ChargeMapper;
import com.biocar.service.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.NoSuchElementException;

/**
 * @author quxiang
 * @date 2021/11/24 16:27
 */
@Service
public class ChargeServiceImpl implements ChargeService {
    @Autowired
    ChargeMapper chargeMapper;

    public Charge selectById(Integer id)
    {
        Charge charge=chargeMapper.selectById(id);
        if(charge==null)
        {
            throw new NoSuchElementException();
        }
        return charge;

    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void deleteById(int id) throws NoSuchElementException
    {
          int i=chargeMapper.deleteById(id);
          if(i==0)
          {
              throw new NoSuchElementException();
          }
    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void insert(Charge charge) throws NoSuchElementException
    {
        int i=chargeMapper.insert(charge);
        if(i==0)
        {
            throw new NoSuchElementException();
        }
    }

    @Transactional(rollbackFor = RuntimeException.class)
    public void update(Charge charge)throws NoSuchElementException
    {
        int i=chargeMapper.updateById(charge);
        if(i==0)
        {
            throw new NoSuchElementException();
        }
    }

}
